package com.laikan.reader.core.adapter;

import android.content.Context;
import android.net.Uri;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.laikan.library.utils.DeviceUtil;
import com.laikan.reader.R;
import com.laikan.reader.core.LaikanBaseAdapter;
import com.laikan.reader.core.bean.RewardBean;
import com.laikan.reader.core.utils.PublicUtil;

import java.util.ArrayList;

public class RewardAdapterNew extends LaikanBaseAdapter<RewardBean> {
    String sum_num;
    public RewardAdapterNew(Context context, ArrayList<RewardBean> datas) {
        super(context, datas);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        ViewHolder holder = null;

        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.lk_reward_item1_new, null);
            holder.reward_count = (TextView)convertView.findViewById(R.id.reward_count);
            holder.person_img = (ImageView)convertView.findViewById(R.id.head_reviewer_img);
            holder.content = (TextView)convertView.findViewById(R.id.content);
            holder.time = (TextView)convertView.findViewById(R.id.time);
            holder.donateContent = (TextView)convertView.findViewById(R.id.donateContent);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        holder.content.setText(Html.fromHtml(datas.get(position).getUserName()));
        holder.reward_count.setText(DeviceUtil.getHtmlFormatedString(mContext, R.string.rewardactivity_reward_count, datas.get(position).getCount()));
        holder.person_img.setImageURI(Uri.parse(datas.get(position).getUserIcon()));
        if(datas.get(position).getDonateContent().length() == 0){
            holder.donateContent.setText(R.string.reward_default_content);
        }else{
            holder.donateContent.setText(datas.get(position).getDonateContent());
        }
        holder.time.setText(PublicUtil.getDateToString(Long.parseLong(datas.get(position).getDonateTime())));
        return convertView;
    }
    private class ViewHolder {
        public ImageView person_img;
        public TextView content, time, donateContent,reward_count;
    }

}
